<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>天下行租车</title>
    <script src="http://47.106.66.89:8080/js/vue.min.js"></script>
    <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
    <link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
    <script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
    <link rel="stylesheet" href="css/base.css">
    <script src="js/txx.js" ></script>
</head>
<body>
<div id="app">
    <my-header></my-header>
    <main class="c900 el-card" style="align-items: stretch; width: 600px;padding: 30px 50px">
        <h2 style="text-align: center;margin-bottom: 50px">用户密码修改</h2>
        <el-row>
            <el-col :span="13" :offset="5">
                <el-form ref="form" label-width="90px">
                    <el-form-item label="新密码">
                        <el-input type="password" v-model="pwd1"></el-input>
                    </el-form-item>
                    <el-form-item label="确认新密码">
                        <el-input type="password" v-model="pwd2"></el-input>
                    </el-form-item>
                    <el-form-item >
                        <small style="color: red">{{massage}}</small>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="save">保存</el-button>
                        <el-button @click="out">取消</el-button>

                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </main>
</div>
<script>
    function getQueryParameter(name) {
        var urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(name);
    }

    // 使用函数获取名为'id'的参数
    var dataFromUrl = getQueryParameter('uname');
    console.log(dataFromUrl); // 输出: example
</script>
<script>
    var v = new Vue({
        el: "#app",
        data:{
            pwd1:'',
            pwd2:'',
            massage:''
        },
        created(){

        },
        methods:{
            save(){

                if(this.pwd1 != this.pwd2){
                    this.massga = '两次输入的新密码不一致';
                    return;
                }
                let p = new URLSearchParams();
                p.append("pwd",this.pwd1);
                p.append("uname",dataFromUrl)
                axios.post("email/setPwd",p).then(res=>{
                    if(res.data.code == 1){
                        alert("密码修改成功,\n用户信息已过期,请重新登录");
                        location.href = "login.html";
                    }else{
                        this.errors.password = res.data.msg;
                    }
                });
            },
            out(){
                window.history.back();
            }

        }
    })
</script>
</body>
</html>
<style>
    .el-form-item .el-form-item {
        margin-bottom: 22px
    }
</style>
